<template>
<div class="page">
        <div class="login_warrper">
            <div class="login_title">你好！请登录</div>
            <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="80px" class="demo-ruleForm">
  <el-form-item label="用户名" prop="name">
    <el-input v-model="ruleForm.name" type="input"></el-input>
  </el-form-item>
  <el-form-item label="密码" prop="password">
    <el-input v-model="ruleForm.password" type="password"></el-input>
  </el-form-item>

 
 
  
</el-form>
 <div class="login_footer">
      <el-button type="primary" @click="login()">登录</el-button>
        <el-button type="success" @click="resetForm()">重置</el-button>
  </div>

        </div>
</div>
</template>
<script>
export default {
    data(){
        return{
         ruleForm:{
             name:"123456",
             password:"123456"
         },
        //  表单验证
         rules: {
          name: [
            { required: true, message: '请输入用户名', trigger: 'blur' },
            { min: 6, max: 16, message: '长度在 6到 16 个字符', trigger: 'blur' }
          ],
            password: [
            { required: true, message: '请输入密码', trigger: 'blur' },
            { min: 6, max: 16, message: '长度在 6 到 16 个字符', trigger: 'blur' }
          ]
         }
        }
    },
    created(){

    },
    methods:{
        login(){
            this.$refs.ruleForm.validate((valid) => {
          if (valid) {
              // this.ruleForm.keys(obj).forEach(item=>{
              //   console.log(item);
              // for (const key in this.ruleForm) {
              //           console.log(this.ruleForm[key]=parseInt(this.ruleForm[key]));
                        
              // }
              
                
              this.$api.getlogin("/api/log",{
                username:this.ruleForm.name,password:this.ruleForm.password
              })
          //  this.$http.post("log",{username:123456,password:123456})
            .then(res=>{
                console.log(res);
                
                if(res.data.code==200){
                         this.$message({
          message: res.data.success,
          type: 'success'
        });
               this.$router.push('/home')

                }else{

              this.$message({
          message: res.data.error,
          type: 'error'
        });
        return
                }

                
            }).catch(error=>{
         

                console.log(error);
                
            })
          } else {

          }
        });
            
        },
        resetForm(){
             this.$refs.ruleForm.resetFields();
            
        }
    }
}
</script>
<style lang="less" scoped>
.page{
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    background-color: #ccc;
    .login_title{
        margin-bottom: 30px;
        text-align: center;
        font-weight: 700;
        font-size: 20px
    }
        .login_warrper{
    position: relative;
        width: 500px;
        height: 280px;
        padding: 20px;
        background-color: #fff;
        border-radius: 20px;
          .login_footer{
        display: flex;
        justify-content: flex-end;
        position: absolute;
        bottom: 0;
        left: 0;
        padding: 30px;
        width: 100%;
       :nth-child(2){
            margin-left: 70px;
        }

    }
    }
  
}
    
</style>
